package fr.esiag.isidis.fi.pdsTeam.UDP;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.util.ArrayList;
import java.util.Date;

import fr.esiag.isidis.fi.pdsTeam.events.RawEvent;
import fr.esiag.isidis.fi.pdsTeam.tablesData.InformationTableModel;
import fr.esiag.isidis.fi.pdsTeam.tram.TramManager;

public class RawInformationReceiver extends Thread{

	Date now=new Date();
	private ArrayList<RawEvent> ev = new ArrayList<RawEvent>();
	
	private InformationTableModel informations = new InformationTableModel();
	
	public InformationTableModel getInformtions() {
		return informations;
	}
	
	void receive(){
		
		RawEvent e;
		
		try{
		 DatagramSocket serverSocket = new DatagramSocket(12345);
         byte[] receiveData = new byte[25];
         //RawInformationParcer parcer=new RawInformationParcer();
         System.out.println("RECEIVER MOCK LOG: En attente des trams...");
            while(true)
            {
               DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
               serverSocket.receive(receivePacket);
               e = new RawEvent(TramManager.extractTram(receiveData, new Date()));
               ev.add(e);
               informations.addInformation(e.getSensorMacAddress(), e.getEventCode(), e.getReceptionTime(), e.getWaitTime());
            }
		}catch(Exception ex){
			System.out.println();
		}
	}
	
	@Override
	public void run() {
		super.run();
		receive();
	}
}